import { request } from '@/api/index.js'

// -------------- 用户模块对应接口 ---------------
// 登录接口请求
export const login = async (user) => {
  return request.post('/api/login', user)
}

// 注册接口请求
export const register = async (user) => {
  return request.post('/api/reg', user)
}

// 获取用户基本信息接口请求
export const getUserInfo = async () => {
  return request.get('/my/userinfo')
}

// --------------分类模块对应接口-----------------

// 获取分类列表的接口请求
export const useTypeListService = async () => {
  return request.get('/my/cate/list')
}

// 获取分类详情的接口请求
export const useTypeDetailService = async (id) => {
  console.log('id', id)
  return request.get(`/my/cate/info?id=${id}`)
}

// 增加分类的接口请求
export const useAddTypeService = async (data) => {
  return request.post('/my/cate/add', data)
}

// 更新分类的接口请求
export const useUpdateTypeService = async (data) => {
  return request.put('/my/cate/info', data)
}

// 删除分类的接口请求
export const useDelTypeService = async (id) => {
  return request.delete(`/my/cate/del?id=${id}`)
}

//-------------- 文章模块对应接口 ----------------------

// 获取分页文章列表的接口请求
export const useArticleListService = async (queryObj) => {
  return request({
    url: '/my/article/list',
    params: queryObj
  })
}

// 删除文章的接口请求
export const useDelArticleService = async (id) => {
  return request.delete(`/my/article/info?id=${id}`)
}

// 获取文章详情的接口请求
export const useGetArtDetailService = async (id) => {
  return request.get(`/my/article/info?id=${id}`)
}

// 增加文章的接口请求
export const useAddArtService = async (data) => {
  return request.post('/my/article/add', data)
}

// 更新-文章详情
export const useSetArtService = async (data) => {
  return request.put('/my/article/info', data)
}

// ------------用户模块对应接口请求----------------

// 更新用户信息的接口请求
export const useSetUserService = async (data) => {
  return request.put('/my/userinfo', data)
}

// 修改密码的接口请求
export const useSetPasswordService = (data) => {
  return request.patch('/my/updatepwd', data)
}

//  更改头像的接口请求
export const useSetAvatarService = (data) => {
  return request.patch('/my/update/avatar', data)
}
